package com.example.bzh.gamecat.httputils.hotlive;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.alibaba.fastjson.JSON;
import com.example.bzh.gamecat.bean.hot.DataBean;
import com.example.bzh.gamecat.util.OkHttpUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

/**
 * Created by peter on 2016/8/18.
 */
public class Hotdata {
    public static void getHotData(final Context context, final String url, final Handler handler) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    String requestExe = OkHttpUtil.getRequestExe(url, context);
                    JSONObject jsonObject = new JSONObject(requestExe);

                    JSONObject data = jsonObject.getJSONObject("data");
                    DataBean dataBean = JSON.parseObject(data.toString(), DataBean.class);
                    Message message = handler.obtainMessage(2, dataBean);
                    handler.sendMessage(message);

                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        }).start();
    }
}